<!DOCTYPE html>
<html lang="zh-CN">
  <head>

	  <%layout("/WEB-INF/view/common/inc/admin_head.html",{title:'添加组织机构', styles:'bootstrap,font-awesome,animate,style,dtvalidate'}){%>
	  <style type="text/css">
		  body{padding-top:10px;}
	  </style>
	  <%}%>

  </head>
  <body>
	<!-- START 内容部分 -->
	<div class="container">
		<form class="form-horizontal" id="info-form" method="post">
			<div class="form-group">
				<label class="col-sm-2 control-label text-right">上级组织机构</label>
				<div class="col-sm-6">
					<div class="input-group">
						<input type="hidden" id="groupPid" name="groupPid" value="${pid}"/>
						<input type="hidden" id="groupLevel" name="groupLevel" value="${parentGroup.groupLevel!""}${pid}_"/>
						<input type="text" id="groupPname" name="groupPname" class="form-control" valid="r" validTitle="上级组织机构" validInfoArea="parentId_info_area" value="${parentGroup.groupName!"无"}"/>
						<span class="input-group-btn">
							<a class="select-btn btn btn-primary"><i class="fa fa-search-plus"></i>  选择</a>
						</span>
					</div>
				</div>
				<div class="col-sm-4"><p class="help-block" id="parentId_info_area"></p></div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label text-right">组织机构名称</label>
				<div class="col-sm-6">
					<input type="text" id="groupName" name="groupName" class="form-control" valid="r|le1-le200" validTitle="组织机构名称" validInfoArea="groupName_info_area" />
				</div>
				<div class="col-sm-4"><p class="help-block" id="groupName_info_area"></p></div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label text-right">组织机构编码</label>
				<div class="col-sm-6">
					<input type="text" id="groupCode" name="groupCode" class="form-control" valid="r|le1-le200" validTitle="组织机构编码" validInfoArea="groupCode_info_area" />
				</div>
				<div class="col-sm-4"><p class="help-block" id="groupCode_info_area"></p></div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label text-right">机构类型</label>
				<div class="col-sm-6">
					<select id="groupType" name="groupType" class="form-control" valid="r" validTitle="组织机构类型" validInfoArea="groupType_info_area" >
						<option value="">选择机构类型</option>
						<%for(var dict in dictFun("group_type","")){%>
						<option value="${dict.detailCode}">${dict.detailName}</option>
						<%}%>
					</select>
				</div>
				<div class="col-sm-4"><p class="help-block" id="groupType_info_area"></p></div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label text-right">组织机构描述</label>
				<div class="col-sm-6">
					<textarea id="groupDesc" name="groupDesc" class="form-control" rows="3"></textarea>
				</div>
				<div class="col-sm-4"></div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label text-right">排序号</label>
				<div class="col-sm-6">
					<input type="text" id="orderId" name="orderId" class="form-control" valid="r|number" validTitle="排序号" validInfoArea="orderId_info_area" value="0"/>
				</div>
				<div class="col-sm-4"><p class="help-block" id="orderId_info_area"></p></div>
			</div>
			
			<div class="form-group">
				<div class="col-sm-offset-2 col-sm-10">
					<button type="button" class="save-btn btn btn-primary">
						<i class="fa fa-save"></i> 保存
					</button>
				</div>
			</div>
		</form>
	</div>
	<!-- END 内容部分 -->
	
	<%layout("/WEB-INF/view/common/inc/admin_js.html",{modules:'jquery,bootstrap,dtvalidate,dtvalidate-lang-zh_cn'}){}%>
	<script>
	var cvalidator;
	$(function(){
		//初始化验证器
		cvalidator = $.fn.dlshouwen.validator.init($('#info-form'));
		
		//选择组织机构
		$('.select-btn').on('click',function(){
			parent.layer.open({
				title: '选择组织机构',
			    type: 2,
			    area: ['500px', '550px'],
			    skin: 'layer-ext-espresso', 
			    content: ['${ctxPath}/power/group/selecttree.do?gid='+$('#groupPid').val(), 'no']
			});
		});
		
		//提交表单
		$('.save-btn').on('click',function(){
			if(!cvalidator.validResult()){
				$.fn.dlshouwen.validator.tools.toast('验证失败！', 'error', 2000);
				return;
			}
			
			//数据提交
			$.post('${ctxPath}/power/group/save.do',$('#info-form').serialize(),function(data){
				if( data.ok ){
					parent.layer.msg(data.msg,{icon:1,time:1500,shade: [0.8, '#393D49']}, function(){
						parent.$powergrouptable.bootstrapTable('refresh');
						var newGroupNode = { id: data.data.id, name: $('#groupName').val() };
						parent.treeObj.addNodes( parent.treeObj.getNodeByParam("id", $('#groupPid').val(), null), newGroupNode);
						parent.layer.close(parent.layer.getFrameIndex(window.name)); //关闭弹窗
					});
				}else{
					parent.layer.msg(data.msg,{icon: 0,time:1500,shade: [0.8, '#393D49']});
				}
			});
		});
    });
    </script>
  </body>
</html>